-
Notifications
You must be signed in to change notification settings - Fork 499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Requests: Add "requests.failed" hook #582
base: develop
Are you sure you want to change the base?
Conversation
Thank you @pprkut . I'm not adverse to this change, but would like to see it covered by unit tests. |
Sure thing, just a bit confused by the test organization 😅 |
I think the most appropriate place for the tests would be in the If needs be, we can always move it later (we're working on improving the test suite). If you need some inspiration on how to test the hook, you may want to have a look at the following tests: Requests/tests/Transport/BaseTestCase.php Lines 924 to 957 in 28879ed
|
Thank you @jrfnl! I will take a look! |
@pprkut Just checking in to see how it's going... |
@jrfnl I still have it on my list, but haven't found the time yet :-/ |
78d0674
to
bc3e608
Compare
@jrfnl I think I got all the different test cases. Let me know what you think :) I'm also fine squashing the commits, etc. Just focused on getting the tests in for now |
29202ff
to
c99d3fc
Compare
Thanks for the work on this PR so far! I have been thinking about this some more, and I actually fail to see what the use case is where you would need this action. I'm not opposed to adding actions, but they need to add something to warrant their added maintenance cost. Here, I'm not sure this is the case. Maybe you can help me figure this out. The way I see it right now, you could get everything you need by adding a Do you have a use case in mind where just adding a |
@schlessera Sure, I'll try to outline our usecase :) We use the hooks to collect analytics about all HTTP requests that our system makes. The end result then looks like this: The hooks we use are:
The way it works is that However, if a request fails, because of wrong options or curl errors, we have the analytics data initiated, but no other hook is triggered so we never get an indicator that the request is "completed" (and that means the anayltics are never stored and won't show on that dashboard). We could do that with exception handling on our side of the code, but then we'd have to either do that everywhere we make an HTTP request with Requests and call the analytics library in all those places to indicate the request is completed and failed, or implement a wrapper around Requests that does that exception handling. But that just seems weird and clunky since most of the functionality is already handled via hooks. Adding the |
Rebased, and I think the "Status: needs tests" label can go now since it has tests. |
8903c86
to
1b165c8
Compare
Rebased after doing some work on our fork accidentally dropped some commits. |
@jrfnl I've been following along the other PR 🙂 |
@pprkut Excellent! Take your time and I look forward to seeing the next iteration. In the mean time: enjoy your break! |
This allows to inspect or alter the exception that is thrown to the user in case of transport errors, or in case of response parsing problems.
…n one catch" Multi-catch is PHP 7.1+, and we still need to support 5.6 This reverts commit 11faa0f.
@jrfnl Should be updated 🙂 |
Pull Request Type
This is a:
Context
This allows to inspect or alter the exception that is thrown to
the user in case of transport errors, or in case of response
parsing problems.
Detailed Description
We use the hooks to gather analytics about the remote requests we make in out platform, but failed requests slipped through the cracks since there is currently no way to track those. You can get some analytics from when you make the request, but you won't know from just that whether it failed. We'd also like to know why it failed, the error message that was returned, etc.
We've been using the hook in our platform for a couple weeks now and it worked fine for us :)
(Although we've applied this change to 1.8.x)
Quality assurance
Documentation
For new features:
examples
directory.docs
directory.If the documentation is in a new markdown file, I have added a link to this new file to the Docs folder
README.md
file.